/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2017 abel533@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package cc.siyecao.mapper.sample;

import cc.siyecao.mapper.sample.domain.User;
import cc.siyecao.mapper.sample.mapper.UserMapper;
import cc.siyecao.mapper.wrapper.LambdaWrapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@MapperScan(basePackages = "cc.siyecao.mapper.sample")
@SpringBootApplication
public class SampleMapperApplication implements CommandLineRunner {

    @Autowired
    private UserMapper userMapper;

//    @Autowired
//    private cc.siyecao.mapper.sample.mapper.DynamicUserMapper dynamicUserMapper;

    public static void main(String[] args) {
        SpringApplication.run( SampleMapperApplication.class, args );
    }

    @Override
    public void run(String... args) throws Exception {
        LambdaWrapper<User> lambdaWrapper = new LambdaWrapper<>();
        lambdaWrapper.set( User::getUserName, "测试更新" ).eq( User::getId, 1 );
        userMapper.updateByWrapperSelective( null, lambdaWrapper );
        userMapper.updateByWrapperSelective( null, lambdaWrapper );
        // userMapper.insert( user );

//        User user1 = new User();
//        user1.setUserName( "测试1" );
//        User user2 = new User();
//        user2.setUserName( "测试2" );
//        User user3 = new User();
//        user3.setUserName( "测试3" );
//        User user4 = new User();
//        user4.setUserName( "测试4" );
//        User user5 = new User();
//        user5.setUserName( "测试5" );
//        User user6 = new User();
//        user6.setUserName( "测试6" );
//        List<User> list = new ArrayList<>();
//        list.add( user1 );
//        list.add( user2 );
//        list.add( user3 );
//        list.add( user4 );
//        list.add( user5 );
//        list.add( user6 );
//
//        userMapper.insertBatchSelective( list );

//        User user1 = new User();
//        user1.setId( 1L );
//        user1.setUserName( "测试1" );
//        User user2 = new User();
//        user1.setId( 2L );
//        user2.setUserName( "测试2" );
//        User user3 = new User();
//        user1.setId( 3L );
//        user3.setUserName( "测试3" );
//        User user4 = new User();
//        user1.setId( 4L );
//        user4.setUserName( "测试4" );
//        User user5 = new User();
//        user1.setId( 5L );
//        user5.setUserName( "测试5" );
//        User user6 = new User();
//        user1.setId( 6L );
//        user6.setUserName( "测试6" );
//        List<User> list = new ArrayList<>();
//        list.add( user1 );
//        list.add( user2 );
//        list.add( user3 );
//        list.add( user4 );
//        list.add( user5 );
//        list.add( user6 );
//
//        userMapper.updateBatchSelective( list );
    }

}
